#!/bin/bash

if [ $(id -u) = 0 ]
then
   echo "This script must not be run as root" 1>&2
   exit
fi

ROOT_PATH=$(cd $(dirname $0) && pwd);

### FFQueue ###

if [ -d "$ROOT_PATH/olive" ]
then

mkdir -p $HOME/Olive
cp -f $ROOT_PATH/olive/olive.png $HOME/Olive/


rm -f -r $HOME/Olive/1
mkdir -p $HOME/Olive/1

for file in $ROOT_PATH/olive/*.AppImage
do
	cp -f ${file} $HOME/Olive/1
	break
done

for file in $HOME/Olive/1/*.AppImage
do
	chmod a+x ${file}

sh -c "echo '[Desktop Entry]
Type=Application
Name=Olive 0.1
Exec='${file}'
Icon=$HOME/Olive/olive.png
Terminal=false
' > $HOME/Desktop/Olive.0.1.desktop"

	chmod a+x $HOME/Desktop/Olive.0.1.desktop

	break
done


rm -f -r $HOME/Olive/2
mkdir -p $HOME/Olive/2

for file in $ROOT_PATH/olive/*.zip
do
	unzip -o ${file} -d $HOME/Olive/2
	break
done

for file in $HOME/Olive/2/*.AppImage
do
	chmod a+x ${file}

sh -c "echo '[Desktop Entry]
Type=Application
Name=Olive 0.2
Exec='${file}'
Icon=$HOME/Olive/olive.png
Terminal=false
' > $HOME/Desktop/Olive.0.2.desktop"

	chmod a+x $HOME/Desktop/Olive.0.2.desktop

	break
done


fi
